package com.itheima.HomeWork_day10;

import java.util.Map;
import java.util.TreeMap;

public class BaseMap02 {
    public static void main(String[] args) {

        Map<String, String> map = new TreeMap<>();


        //V put(K key,V value)：添加元素
        map.put("小龙女","杨过");
        map.put("郭靖","黄蓉");
        map.put("梁山伯","祝英台");
        map.put("至尊宝","紫霞");

        //V remove(Object key)：根据键删除键值对元素
        remoMethod1(map);

        //boolean containsKey(Object key)：判断集合是否包含指定的键
        conMethod2(map);

        //int size()：集合的长度，也就是集合中键值对的个数
        sizeMethod4(map);

//boolean isEmpty()：判断集合是否为空
        emptyMethod3(map);
        //void clear()：移除所有的键值对元素
      clearMethod4(map);

    }

    private static void sizeMethod4(Map<String, String> map) {
        int size = map.size();
        System.out.println(size);
        System.out.println("==========================");
    }

    private static void clearMethod4(Map<String, String> map) {
        map.clear();
        boolean empty1 = map.isEmpty();
        System.out.println(empty1);
        System.out.println("=====================");
    }

    private static void emptyMethod3(Map<String, String> map) {
        boolean empty = map.isEmpty();
        System.out.println(empty);
        System.out.println("===================");
    }

    private static void conMethod2(Map<String, String> map) {
        boolean containsKey = map.containsKey("小龙女");
        System.out.println(containsKey);
        System.out.println("=================");
        boolean containsValue = map.containsValue("段誉");
        System.out.println(containsValue);
    }

    private static void remoMethod1(Map<String, String> map) {
        String remove = map.remove("郭靖");
        System.out.println(remove);
        System.out.println(map);

    }
}
